$(document).ready(function () {
    // APP 状态下拉列表
    $.get("dataDictionary/getAppState",{'flag':false},function (json) {
        dataDictionaryOption(json,$('.appState'))
    });

    // APP 平台
    $.get("dataDictionary/getAppPlatform",{'flag':true},function (json) {
        dataDictionaryOption(json,$('.appPlatform'))
    });

    function dataDictionaryOption(json,element) {
        if( json ) {
            $(json).each(function () {
                var option= new Option(this.valueName,this.valueId);
                element.get(0).add(option);
            });
        }
    }

    var appCategoryUrl= "appCategory/showAppCategory";
    //分类 三级联动
    $.getJSON(appCategoryUrl,{'parentId':0},function (json) {
        //初始化
        appCategoryOption(json,$('.levelOne'));
        // 一级分类改变
        $('.levelOne').on('change', function () {
            $('.levelTwo').html("<option value=\"-1\">请选择</option>");
            levelTwo($(this).val());

            $('.levelTwo').on('change',function () {
                $('.levelThree').html("<option value=\"-1\">请选择</option>");
                levelThree($(this).val())
            });
        });

    });

//二级分类
    function levelTwo(oneValue) {
        $.getJSON(appCategoryUrl,{'parentId':oneValue},function (json) {
            appCategoryOption(json,$('.levelTwo'))
        });
    }

//三级分类
    function levelThree(twoValue) {
        $.getJSON(appCategoryUrl,{'parentId':twoValue},function (json) {
            appCategoryOption(json,$('.levelThree'))
        });
    }

    function appCategoryOption(json,element) {
        if( json ) {
            $(json).each(function () {
                var option= new Option(this.categoryName,this.id);
                element.get(0).add(option);
            });
        }
    }
});